package com.war.controller.system;

import com.war.pojo.system.Customer;
import com.war.service.safeManage.UserService;
import com.war.service.system.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired(required = false)
    CustomerService customerService;

    @RequestMapping("/selectName")
    @ResponseBody
    public List<Customer> selectName(){
        return customerService.selectName();
    }

    //访问warehouseManage页面
    @RequestMapping("/customerList")
    public String list(Customer customer, ModelMap m){
        //查询分页数据
        HashMap<String, Object> map = customerService.select(customer);        //把数据传到前端
        m.put("info",map);
        //把查询条件传到前端
        m.put("CV",customer.getConValue());
        return "basicDataManage/customerManage/customerManage";
    }

    //打开添加页面
    @RequestMapping("/addCusPage")
    public String addCusPage(){
        return "basicDataManage/customerManage/addCus";
    }

    //打开修改页面
    @RequestMapping("/editCusPage")
    public String editCusPage(Customer customer, ModelMap m){
        Customer c = customerService.selectByid(customer);
        //把数据传到前端
        m.addAttribute("customer",c);
        return "basicDataManage/customerManage/editCus";
    }

    //处理修改的ajax请求
    @RequestMapping("/editCus")
    @ResponseBody
    public HashMap<String,Object> editCus(Customer customer){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = customerService.editCus(customer);
        map.put("info",info);
        return map;
    }

    //处理删除的ajax请求
    @RequestMapping("/delCus")
    @ResponseBody
    public HashMap<String,Object> delCus(Customer customer){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = customerService.delCus(customer);
        map.put("info",info);
        return map;
    }

    //处理添加用户的ajax请求
    @RequestMapping("/addCus")
    @ResponseBody
    public HashMap<String,Object> addCus(Customer customer){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = customerService.addCus(customer);
        map.put("info",info);
        return map;
    }

}
